/*aparece no turtle
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormAberturaChamados.java
 *
 * Created on 06/12/2011, 01:13:30
 */

package sistemachamados.view;

import classes.CategoriaChamado;
import classes.Chamado;
import classes.StatusChamado;
import classes.Usuario;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Cleber Lopes
 */
public class FormEncerramentoChamados extends javax.swing.JInternalFrame {
//public class FormAberturaChamados extends JDialog {
    /** Creates new form FormAberturaChamados */

    private Usuario usuarioLogado;

    public FormEncerramentoChamados() {
        initComponents();
    }

    public FormEncerramentoChamados(Usuario usuarioLogado) {
        initComponents();
        this.usuarioLogado = usuarioLogado;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnAtender = new javax.swing.JButton();
        btnRepassar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblChamadosSemAtendimento = new javax.swing.JTable();
        cbxUsuarioRepassar = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblChamadosEmAtendimento = new javax.swing.JTable();
        btnEncerrarChamado = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        btnNovoAssentamento = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtAssentamentos = new javax.swing.JTextArea();
        jButton5 = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtSolucao = new javax.swing.JTextArea();
        jLabel5 = new javax.swing.JLabel();

        setBorder(null);
        setClosable(true);
        setFrameIcon(null);
        setInheritsPopupMenu(true);
        setMinimumSize(new java.awt.Dimension(990, 470));
        setPreferredSize(new java.awt.Dimension(990, 470));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CHAMADOS EM ESPERA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Showcard Gothic", 0, 16))); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(FormEncerramentoChamados.class);
        jPanel1.setFont(resourceMap.getFont("jPanel1.font")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setOpaque(false);

        btnAtender.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnAtender.setText("Atender");
        btnAtender.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnAtender.setName("btnAtender"); // NOI18N
        btnAtender.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtenderActionPerformed(evt);
            }
        });

        btnRepassar.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnRepassar.setText("Repassar");
        btnRepassar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnRepassar.setName("btnRepassar"); // NOI18N
        btnRepassar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRepassarActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tblChamadosSemAtendimento.setFont(new java.awt.Font("Tahoma", 0, 12));
        tblChamadosSemAtendimento.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Número do chamado", "Data de abertura", "Problema", "Solicitante", "Status do chamado", "Categoria do chamado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblChamadosSemAtendimento.setCellSelectionEnabled(true);
        tblChamadosSemAtendimento.setName("tblChamadosSemAtendimento"); // NOI18N
        tblChamadosSemAtendimento.getTableHeader().setResizingAllowed(false);
        tblChamadosSemAtendimento.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tblChamadosSemAtendimento);

        cbxUsuarioRepassar.setFont(new java.awt.Font("Century Gothic", 0, 14));
        cbxUsuarioRepassar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione um usuário ..." }));
        cbxUsuarioRepassar.setName("cbxUsuarioRepassar"); // NOI18N

        jLabel10.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel10.setText("Usuário");
        jLabel10.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel10.setAlignmentY(0.0F);
        jLabel10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 657, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addComponent(btnAtender)
                        .addGap(18, 18, 18)
                        .addComponent(btnRepassar, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(78, 78, 78))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbxUsuarioRepassar, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(59, 59, 59))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnAtender)
                            .addComponent(btnRepassar))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxUsuarioRepassar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(9, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 20, 1014, 150);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CHAMADOS EM ATENDIMENTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Showcard Gothic", 0, 16))); // NOI18N
        jPanel2.setFont(new java.awt.Font("Showcard Gothic", 0, 16));
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setOpaque(false);
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblChamadosEmAtendimento.setFont(new java.awt.Font("Tahoma", 0, 12));
        tblChamadosEmAtendimento.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Número do chamado", "Data de abertura", "Problema", "Solicitante", "Status do chamado", "Categoria do chamado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblChamadosEmAtendimento.setCellSelectionEnabled(true);
        tblChamadosEmAtendimento.setName("tblChamadosEmAtendimento"); // NOI18N
        tblChamadosEmAtendimento.getTableHeader().setResizingAllowed(false);
        tblChamadosEmAtendimento.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblChamadosEmAtendimento);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 650, 100));

        btnEncerrarChamado.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnEncerrarChamado.setText("Encerrar Chamado");
        btnEncerrarChamado.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnEncerrarChamado.setName("btnEncerrarChamado"); // NOI18N
        btnEncerrarChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEncerrarChamadoActionPerformed(evt);
            }
        });
        jPanel2.add(btnEncerrarChamado, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 200, 260, -1));

        jLabel11.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel11.setText("Assentamentos");
        jLabel11.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel11.setAlignmentY(0.0F);
        jLabel11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel11.setName("jLabel11"); // NOI18N
        jPanel2.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, 120, -1));

        btnNovoAssentamento.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnNovoAssentamento.setText("Novo");
        btnNovoAssentamento.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnNovoAssentamento.setName("btnNovoAssentamento"); // NOI18N
        btnNovoAssentamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoAssentamentoActionPerformed(evt);
            }
        });
        jPanel2.add(btnNovoAssentamento, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 140, 110, -1));

        jButton4.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        jButton4.setText("Cancelar");
        jButton4.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 200, 110, -1));

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        txtAssentamentos.setColumns(20);
        txtAssentamentos.setRows(5);
        txtAssentamentos.setName("txtAssentamentos"); // NOI18N
        jScrollPane3.setViewportView(txtAssentamentos);

        jPanel2.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 150, 530, 80));

        jButton5.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        jButton5.setText("Salvar");
        jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 170, 110, -1));

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        txtSolucao.setColumns(20);
        txtSolucao.setRows(5);
        txtSolucao.setName("txtSolucao"); // NOI18N
        jScrollPane4.setViewportView(txtSolucao);

        jPanel2.add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 30, 260, 160));

        getContentPane().add(jPanel2);
        jPanel2.setBounds(10, 180, 960, 240);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemachamados/view/resources/FORM PRINCIPAL (FUNDOPANEL).png"))); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        getContentPane().add(jLabel5);
        jLabel5.setBounds(0, 0, 980, 460);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        updateDataInScreen();
    }//GEN-LAST:event_formComponentShown

    private void btnAtenderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtenderActionPerformed
        Chamado chamadoModificado = new Chamado();
        int lineOftable = tblChamadosSemAtendimento.getSelectedRow();
        chamadoModificado.setId((Integer)tblChamadosSemAtendimento.getValueAt(lineOftable, 0));
        chamadoModificado.setDataAbertura((Date)tblChamadosSemAtendimento.getValueAt(lineOftable, 1));
        chamadoModificado.setDescrProblema((String)tblChamadosSemAtendimento.getValueAt(lineOftable, 2));
        chamadoModificado.setUsuarioAbertura((Usuario)new Usuario()
                                            .selecionar((String)tblChamadosSemAtendimento.getValueAt(lineOftable, 3)));
        chamadoModificado.setStatus(new StatusChamado().selecionar(2)); //Fixo porque 2 é em atendimento
        chamadoModificado.setCategoria(new CategoriaChamado().selecionar((String)tblChamadosSemAtendimento.getValueAt(lineOftable, 5)));
        if(chamadoModificado.alterar(usuarioLogado))
        {
            JOptionPane.showMessageDialog(this,
                    "O chamado agora está em atendimento.",
                    "Sucesso!",
                    JOptionPane.INFORMATION_MESSAGE);
            updateDataInScreen();
        }
        else
        {
            JOptionPane.showMessageDialog(this,
                    "Houve um erro ao processar a requisição.",
                    "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnAtenderActionPerformed

    private void btnRepassarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRepassarActionPerformed
        Chamado chamadoModificado = new Chamado();
        int lineOftable = tblChamadosSemAtendimento.getSelectedRow();
        chamadoModificado.setId((Integer)tblChamadosSemAtendimento.getValueAt(lineOftable, 0));
        chamadoModificado.setDataAbertura((Date)tblChamadosSemAtendimento.getValueAt(lineOftable, 1));
        chamadoModificado.setDescrProblema((String)tblChamadosSemAtendimento.getValueAt(lineOftable, 2));
        chamadoModificado.setUsuarioAbertura((Usuario)new Usuario()
                                            .selecionar((Integer)tblChamadosSemAtendimento.getValueAt(lineOftable, 3)));
        chamadoModificado.setStatus(new StatusChamado().selecionar(2)); //Fixo porque 2 é em atendimento
        chamadoModificado.setCategoria(new CategoriaChamado().selecionar((Integer)tblChamadosSemAtendimento.getValueAt(lineOftable, 6)));
        if(chamadoModificado.alterar((Usuario)cbxUsuarioRepassar.getSelectedItem()))
        {
            JOptionPane.showMessageDialog(this,
                    "O chamado agora está em atendimento.",
                    "Sucesso!",
                    JOptionPane.INFORMATION_MESSAGE);
            updateDataInScreen();
        }
        else
        {
            JOptionPane.showMessageDialog(this,
                    "Houve um erro ao processar a requisição.",
                    "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnRepassarActionPerformed

    private void btnNovoAssentamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoAssentamentoActionPerformed
        txtAssentamentos.setText("");
        txtAssentamentos.setEnabled(true);
        txtAssentamentos.setEditable(true);
        txtAssentamentos.setFocusable(true);
    }//GEN-LAST:event_btnNovoAssentamentoActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        Chamado chamado = new Chamado();
        chamado.setId((Integer)tblChamadosEmAtendimento.getValueAt(tblChamadosEmAtendimento.getSelectedRow(), 0));
        if(chamado.insertAssentamentoChamado(txtAssentamentos.getText()))
        {
            JOptionPane.showMessageDialog(this,
                    "O assentameto foi incluído.",
                    "Sucesso!",
                    JOptionPane.INFORMATION_MESSAGE);
            updateDataInScreen();
        }
        else
        {
            JOptionPane.showMessageDialog(this,
                    "Houve um erro ao processar a requisição.",
                    "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        updateDataInScreen();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void btnEncerrarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEncerrarChamadoActionPerformed
        Chamado chamadoModificado = new Chamado();
        int lineOftable = tblChamadosEmAtendimento.getSelectedRow();
        chamadoModificado.setId((Integer)tblChamadosEmAtendimento.getValueAt(lineOftable, 0));
        chamadoModificado.setDataAbertura((Date)tblChamadosEmAtendimento.getValueAt(lineOftable, 1));
        chamadoModificado.setDescrProblema((String)tblChamadosEmAtendimento.getValueAt(lineOftable, 2));
        chamadoModificado.setUsuarioAbertura((Usuario)new Usuario()
                                            .selecionar((String)tblChamadosEmAtendimento.getValueAt(lineOftable, 3)));
        chamadoModificado.setStatus(new StatusChamado().selecionar(3)); //Fixo porque 3 é em atendimento
        chamadoModificado.setCategoria(new CategoriaChamado().selecionar((String)tblChamadosEmAtendimento.getValueAt(lineOftable, 5)));
        chamadoModificado.setDescrSolucao(txtSolucao.getText());
        if(chamadoModificado.alterar(usuarioLogado))
        {
            JOptionPane.showMessageDialog(this,
                    "O chamado agora está em atendimento.",
                    "Sucesso!",
                    JOptionPane.INFORMATION_MESSAGE);
            updateDataInScreen();
        }
        else
        {
            JOptionPane.showMessageDialog(this,
                    "Houve um erro ao processar a requisição.",
                    "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnEncerrarChamadoActionPerformed

    public void getAssentamentosFromChamado(int idChamado)
    {
        //Pegar os assentamentos da tabela de assentamentos...
        Chamado chamado = new Chamado();
        chamado.setId(idChamado);
        ArrayList<String> listAssentamentos = chamado.getAssentamentosChamado();
        for(String assent : listAssentamentos)
        {
            txtAssentamentos.setText(txtAssentamentos.getText() + "\n\n"+
                                     assent);
        }
    }

    public void updateDataInScreen()
    {
        Chamado chamado = new Chamado();
        ArrayList<Chamado> listChamado = chamado.getChamadosSemAtendimento();
        DefaultTableModel model = (DefaultTableModel) tblChamadosSemAtendimento.getModel();
        model.setRowCount(0);
        for(int i = 0; i < listChamado.size(); i++)
        {
            Object[] data = new Object[6];
            data[0] = listChamado.get(i).getId();
            data[1] = listChamado.get(i).getDataAbertura();
            data[2] = listChamado.get(i).getDescrProblema();
            data[3] = listChamado.get(i).getUsuarioAbertura().getNome();
            data[4] = listChamado.get(i).getStatus().getDescr();
            data[5] = listChamado.get(i).getCategoria().getDescr();
            model.addRow(data);
        }
        tblChamadosSemAtendimento.setModel(model);

        Chamado chamadoAtend = new Chamado();
        ArrayList<Chamado> listChamadoAtend = chamado.getChamadosEmAtendimento(usuarioLogado);
        DefaultTableModel modelAtend = (DefaultTableModel) tblChamadosEmAtendimento.getModel();
        modelAtend.setRowCount(0);
        for(int j = 0; j < listChamadoAtend.size(); j++)
        {
            Object[] data = new Object[6];
            data[0] = listChamadoAtend.get(j).getId();
            data[1] = listChamadoAtend.get(j).getDataAbertura();
            data[2] = listChamadoAtend.get(j).getDescrProblema();
            data[3] = listChamadoAtend.get(j).getUsuarioAbertura().getNome();
            data[4] = listChamadoAtend.get(j).getStatus().getDescr();
            data[5] = listChamadoAtend.get(j).getCategoria().getDescr();
            modelAtend.addRow(data);
        }
        tblChamadosEmAtendimento.setModel(modelAtend);

        ArrayList<Usuario> listUsuarios = (new Usuario()).selecionar();
        if(!listUsuarios.isEmpty()) {
            DefaultComboBoxModel modelCombo = new DefaultComboBoxModel(listUsuarios.toArray());
            cbxUsuarioRepassar.setModel(modelCombo);
        }

        if(tblChamadosEmAtendimento.getRowCount() > 0)
        {
             getAssentamentosFromChamado((Integer)tblChamadosEmAtendimento.getValueAt(0, 0));
        }
        txtAssentamentos.setEnabled(false);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAtender;
    private javax.swing.JButton btnEncerrarChamado;
    private javax.swing.JButton btnNovoAssentamento;
    private javax.swing.JButton btnRepassar;
    private javax.swing.JComboBox cbxUsuarioRepassar;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable tblChamadosEmAtendimento;
    private javax.swing.JTable tblChamadosSemAtendimento;
    private javax.swing.JTextArea txtAssentamentos;
    private javax.swing.JTextArea txtSolucao;
    // End of variables declaration//GEN-END:variables

}
